package com.b2b.util;

import com.b2b.model.ReceivingInfoDto;
import com.b2b.model.entity.ReceivingInfo;
import com.b2b.service.ReceivingInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ReceivingInfoUtil {
    private final ReceivingInfoService receivingInfoService;
    @Autowired
    public ReceivingInfoUtil(ReceivingInfoService receivingInfoService){
        this.receivingInfoService = receivingInfoService;
    }

    public Integer insertReceivingInfo(ReceivingInfoDto receivingInfoDto){
        ReceivingInfo receivingInfo = getReceivingInfo(receivingInfoDto);
        Integer count = receivingInfoService.insert(receivingInfo);
        if (count <= 0){
            return count;
        }else {
            count = receivingInfo.getReceivingInfoId();
            return count;
        }
    }

    public ReceivingInfo selectReceivingInfo(Integer receivingInfoId){
        ReceivingInfo receivingInfo = new ReceivingInfo();
        receivingInfo.setReceivingInfoId(receivingInfoId);
        receivingInfo = receivingInfoService.selectByPrimaryKey(receivingInfo);
        return receivingInfo;
    }

    public Integer deleteReceivingInfo(Integer receivingInfoId){
        ReceivingInfo receivingInfo = new ReceivingInfo();
        receivingInfo.setReceivingInfoId(receivingInfoId);
        Integer count = receivingInfoService.deleteByPrimaryKey(receivingInfo);
        return count;
    }

    public Integer updateReceivingInfo(ReceivingInfoDto receivingInfoDto){
        ReceivingInfo receivingInfo = getReceivingInfo(receivingInfoDto);
        Integer count = receivingInfoService.updateByPrimaryKeySelective(receivingInfo);
        return count;
    }
    public ReceivingInfoDto getReceivingInfoDto(ReceivingInfo receivingInfo){
        ReceivingInfoDto receivingInfoDto = new ReceivingInfoDto();
        receivingInfoDto.setReceivingInfoId(receivingInfo.getReceivingInfoId());
        receivingInfoDto.setReceiver(receivingInfo.getReceiver());
        receivingInfoDto.setAddress(receivingInfo.getAddress());
        receivingInfoDto.setPhone(receivingInfo.getPhone());
        receivingInfoDto.setProvince(receivingInfo.getProvince());
        receivingInfoDto.setCity(receivingInfo.getCity());
        receivingInfoDto.setDistrict(receivingInfo.getDistrict());
        receivingInfoDto.setCompanyId(receivingInfo.getCompanyId());
        return receivingInfoDto;
    }

    public ReceivingInfo getReceivingInfo(ReceivingInfoDto receivingInfoDto){
        ReceivingInfo receivingInfo = new ReceivingInfo();
        receivingInfo.setReceivingInfoId(receivingInfoDto.getReceivingInfoId());
        receivingInfo.setReceiver(receivingInfoDto.getReceiver());
        receivingInfo.setAddress(receivingInfoDto.getAddress());
        receivingInfo.setPhone(receivingInfoDto.getPhone());
        receivingInfo.setProvince(receivingInfoDto.getProvince());
        receivingInfo.setCity(receivingInfoDto.getCity());
        receivingInfo.setDistrict(receivingInfoDto.getDistrict());
        receivingInfo.setCompanyId(receivingInfoDto.getCompanyId());
        return receivingInfo;
    }

}
